package com.ease.common.vo;

import java.io.Serializable;
import java.util.List;

/**
 * 
 * @author nathanleewei
 * 
 * @param <T>
 */
public class Pagination<T> implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -7792842238295914694L;

	public static final int SIZE = 20;

	/** items */
	private List<T> items;

	/** page index */
	private int index = 1;

	/** size */
	private int size = SIZE;

	/** count */
	private int count = -1;

	/**
	 * count or not rename as countable to avoid 是否count and 已count
	 * */
	private boolean counted = false;

	public Pagination() {
		this(SIZE);
	}

	public Pagination(int size) {
		this.size = (size < 1) ? SIZE : size;
	}

	public Pagination(List<T> items, int count, int index, int size) {
		this.setItems(items);
		this.setCount(count);
		this.setIndex(index);
		this.setSize(size);
	}

	/**
	 * get item index
	 * 
	 * @return
	 */
	public int getStart() {
		return (this.index - 1) * size;

	}

	/**
	 * item count in current page
	 * 
	 * @return
	 */
	public int getLength() {
		if (null != items) {
			return items.size();
		}
		return 0;
	}

	/**
	 * pages count
	 * 
	 * @return
	 */
	public int getPages() {
		if (this.count > 0 && this.size > 0) {
			return ((count + size - 1) / size);
		}
		return 0;
	}

	/**
	 * @return Returns the items.
	 */
	public List<T> getItems() {
		return items;
	}

	/**
	 * @param items
	 *            The items to set.
	 */
	public void setItems(List<T> items) {
		this.items = items;
	}

	/**
	 * @return Returns the index.
	 */
	public int getIndex() {
		return index;
	}

	/**
	 * @param index
	 *            The index to set.
	 */
	public void setIndex(int index) {
		this.index = index;
	}

	/**
	 * @return Returns the size.
	 */
	public int getSize() {
		return size;
	}

	/**
	 * @param size
	 *            The size to set.
	 */
	public void setSize(int size) {
		this.size = size;
	}

	/**
	 * @return Returns the count.
	 */
	public int getCount() {
		return count;
	}

	/**
	 * @param count
	 *            The count to set.
	 */
	public void setCount(int count) {
		this.count = count;
	}

	/**
	 * @return the counted
	 */
	public boolean isCounted() {
		return counted;
	}

	/**
	 * @param counted
	 *            the counted to set
	 */
	public void setCounted(boolean counted) {
		this.counted = counted;
	}

}
